package com.example.demo.utils.jdkdongtaidaili;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserHandler implements InvocationHandler {
    private Object target;
    public UserHandler(Object target){
        this.target = target;
    }
    /**
     * 获取被代理接口实例对象
     * @param <T>
     * @return
     */
    public <T> T getProxy() {
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("执行前。。。");
        method.invoke(target);
//        method.invoke(proxy);
        System.out.println("执行之后");
        return null;
    }
}
